 IF EXISTS (SELECT * 
	   FROM   sysobjects 
	   WHERE  name = N'spm_GetTreeID')
	DROP FUNCTION spm_GetTreeID
GO

CREATE FUNCTION spm_GetTreeID
(
@TreeID int,
@LinkTreeID int
)
RETURNS int
AS
BEGIN
	if( @LinkTreeID is null)
	begin
		return @TreeID
	end
	return @LinkTreeID
END
